<script setup>
import { ref } from "vue";
import { storeToRefs } from "pinia";
import { musicStore } from "@/store/music";
import { ipcRendererSend } from "../../utils/ipcRenderer";
import { Local } from "../../utils/storage";
const { songListIds, musicDetail, songId } = storeToRefs(musicStore());

const props = defineProps(['songList'])

const handlePlay = (item) => {
  musicDetail.value = item;
  songListIds.value = props.songList;
  Local.set("songList", props.songList);
  Local.set("musicInfo", item);
  songId.value = item.id;
  ipcRendererSend("windows-param", {
    emit: "playMusic",
    data: item.id,
    targetName: "home",
  });
};
</script>

<template>
  <div v-if="songList" class="singer_song">
    <div class="list">
      <div
        @dblclick="handlePlay(item)"
        :class="{ active_position: item.id === songId }"
        v-for="item in songList"
        :key="item.id"
        class="item"
      >
        <div class="left">
          <el-image
            lazy
            style="width: 35px; height: 35px; border-radius: 5px"
            :src="item.al.picUrl+`${'?param=100y100'}}`"
            fit="cover"
          ></el-image>
        </div>
        <div class="right">
          <div class="music_name">{{ item.name }}</div>
          <span
            v-for="(item1, index1) in item.ar"
            :key="index1"
            class="singer_name"
            >{{ item1.name }}
          </span>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.singer_song {
  .list {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    align-items: center;
    .item {
      cursor: pointer;
      display: flex;
      align-items: center;
      width: 21%;
      background-color: #fff;
      padding: 5px;
      border-radius: 10px;
      margin-top: 10px;
      &:hover {
        background-color: #f2f2f4;
      }

      .left {
      }
      .right {
        margin-left: 13px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        .music_name {
          font-size: 16px;
          font-weight: 600;
        }
        .singer_name {
          color: rgb(100, 89, 89);
          font-size: 12px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }
    }
    .active_position {
      color: #335eea;
      background: #eaeffd;
      .right {
        div,
        span {
          color: #335eea;
        }
        .singer_name {
          span {
            color: #335eea;
          }
        }
      }
    }
  }
}
</style>
